package com.nhjf.dao.teachers;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.ArtPicturesComment;
import com.nhjf.pojo.qo.teachers.ArtPicturesCommentQo;
@Repository
public class ArtPicturesCommentDao extends BaseDao<ArtPicturesComment,ArtPicturesCommentQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, ArtPicturesCommentQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("user", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getArtPicturesId()!=null) {
				criteria.setFetchMode("artPictures",FetchMode.JOIN);
				criteria.add(Restrictions.eq("artPictures.id",qo.getArtPicturesId()));
			}
			if(qo.getUserId()!=null) {
				criteria.add(Restrictions.eq("user.id",qo.getUserId()));
			}
			if(qo.getCommentUserType()!=null) {
				criteria.add(Restrictions.eq("commentUserType",qo.getCommentUserType()));
			}
			if(qo.getCommentType()!=null) {
				criteria.add(Restrictions.eq("commentType",qo.getCommentType()));
			}
			if(qo.getCommentTime()!=null) {
				criteria.add(Restrictions.eq("commentTime",qo.getCommentTime()));
			}
			 criteria.addOrder(Order.desc("commentTime"));
		}
		return criteria;
	}

	@Override
	protected Class<ArtPicturesComment> getEntityClass() {
		// TODO Auto-generated method stub
		return ArtPicturesComment.class;
	}

}
